(function () {
    // 验证码
    const imgcode = document.querySelector('.imgcode');
    imgcode.addEventListener('click', imgCodeFn);
    function imgCodeFn() {
        this.src = '/api/code?' + new Date().valueOf();
    }
    // 找回密码
    let btnReset = document.querySelector('.btn-reset');
    btnReset.addEventListener('click', resetFn);

    function resetFn() {
        /** 获取输入框输入的信息 */
        const tel = document.querySelector('input[name="resettel"]').value;
        const passwd = document.querySelector('input[name="resetpd"]').value;
        const code = document.querySelector('input[name="resetcode"]').value;
        const tip4 = document.querySelector('#tip4');
        console.log(tel, passwd, code);

        tip4.style.display = 'block';
        $(function () {
            $('#tip4').addClass('animated bounceInDown');
        });
        setTimeout(() => {
            tip4.style.display = 'none';
        }, 3000)
        document.querySelector('input[name="tel"]').value = tel;
        document.querySelector('input[name="passwd"]').value = passwd;
        /** 把数据提交给后端进行验证 */
        axios.post('/api/reset', {
            tel, passwd, code
        }).then(function (res) {
            const r = res.data;
            console.log(r);
            if (r.code === 1) {
                tip4.innerHTML = r.msg;
                sessionStorage.setItem('regtel', r.regtel);
                setTimeout(() => {
                    document.querySelector('.login-box').style.left = 0 + 'px';
                }, 1500);
            } else if (r.code === -1) {
                tip4.innerHTML = r.msg;
            } else if (r.code === 0) {
                tip4.innerHTML = r.msg;
            } else {
                tip4.innerHTML = r.msg;
            }
        }).catch(function (error) {
            console.log(error);
        });
    }
})();